package cc.fs.kotlin.ui

import android.app.Application
import android.content.Intent
import android.os.Looper
import android.support.v7.app.AlertDialog
import android.widget.Toast
import cc.fs.kotlin.ui.activity.MainActivity
import cc.fs.kotlin.ui.activity.helper.DefaultExceptionHandler
import org.jetbrains.anko.intentFor

/**
 * Created by fostion on 1/28/16.
 */
class App : Application() {

    override fun onCreate() {
        super.onCreate()
        instanceTmp = this

        DefaultExceptionHandler.registUncaughtExceptionHandler(object : DefaultExceptionHandler.OnExceptionListener {
            override fun onException(exception: DefaultExceptionHandler.AppException) {
                //todo 发送错误报告给服务器 并　给出错误提示
                try{
                    Toast.makeText(applicationContext,"app出现意外错误，请重新启动",Toast.LENGTH_SHORT).show()
                    Thread.sleep(2000)
                    System.exit(0)
                }catch(e:Exception){
                    e.printStackTrace()
                }
            }
        })
    }

    companion object {
        private var instanceTmp: App? = null

        public val instance: App by lazy {
            instanceTmp!!
        }
    }

}